package com.lc.user.express.httpserver;

import com.lc.user.express.model.CityModel;
import com.lc.user.express.model.PreferentialModel;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/4/22.优惠活动
 */
@HttpInlet(Net.GET_ACTIVITY_LIST)
public class GetActivityList extends ZJDBAsyGet<GetActivityList.Info> {


    public GetActivityList(AsyCallBack listener) {
        super(listener);
    }

    @Override
    protected Info parser(JSONObject object) {
        if (object.optInt("message") == 1) {
            Info info = new Info();
            JSONArray array = object.optJSONArray("list");

            if(array != null){
                for (int i = 0; i<array.length(); i++){
                    JSONObject jsonObject = array.optJSONObject(i);
                    PreferentialModel model = new PreferentialModel();
                    model.setPicUrl(Net.SERVER+jsonObject.optString("picurl"));
                    model.setTitle(jsonObject.optString("title"));
                    model.setId(jsonObject.optString("id"));
                    info.dataList.add(model);
                }

            }
            return info;
        }
        return null;
    }

    public static class Info {
        public List<PreferentialModel> dataList = new ArrayList<>();
    }
}